package com.zbkj.crmeb.merchant.admin.controller;

import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.common.PageParamRequest;
import com.zbkj.crmeb.marketing.request.StoreCouponUserSearchRequest;
import com.zbkj.crmeb.marketing.response.StoreCouponUserResponse;
import com.zbkj.crmeb.marketing.service.StoreCouponUserService;
import com.zbkj.crmeb.store.model.StoreOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * 优惠券发放记录表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/mer/marketing/coupon/user")
@Api(tags = "营销 -- 优惠券 -- 领取记录")
public class MerStoreCouponUserController extends AdminBaseController {

    @Autowired
    private StoreCouponUserService storeCouponUserService;

    /**
     * 优惠券用户列表
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "优惠券用户列表")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<StoreCouponUserResponse>> listCouponUsers(@Validated StoreCouponUserSearchRequest searchRequest,
                                                                             HttpServletRequest request,
                                                                             @Validated PageParamRequest pageParamRequest) {
        searchRequest.setMerId(getMerId(request));
        CommonPage<StoreCouponUserResponse> storeCouponCommonPage = storeCouponUserService.pageFrontCouponUsers(searchRequest, pageParamRequest);
        return CommonResult.success(storeCouponCommonPage);
    }

    /**
     * 优惠券订单号
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "优惠券用户订单号列表")
    @GetMapping(value = "/orderIds")
    public CommonResult<CommonPage<StoreOrder>> listCouponUserOrderIds(@Validated StoreCouponUserSearchRequest searchRequest,
                                                                       HttpServletRequest request,
                                                                       @Validated PageParamRequest pageParamRequest) {
        searchRequest.setMerId(getMerId(request));
        CommonPage<StoreOrder> storeCouponCommonPage = CommonPage.restPage(storeCouponUserService.listCouponUserOrderIds(searchRequest, pageParamRequest));
        return CommonResult.success(storeCouponCommonPage);
    }

}



